home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / apps / dcopidlng / Ast.pm next >
Text File  |  2005-09-10  |  1KB  |  52 lines

  1. package Ast;
  2. use strict;
  3.  
  4. use vars qw/ $this $pack @endCodes /;
  5.  
  6. #-----------------------------------------------------------------------------
  7. # This package is used  to create a simple Abstract Syntax tree. Each node
  8. # in the AST is an associative array and supports two kinds of properties -
  9. # scalars and lists of scalars.
  10. # See SchemParser.pm for an example of usage.
  11. #                                                               ... Sriram
  12. #-----------------------------------------------------------------------------
  13.  
  14. # Constructor 
  15. # e.g AST::New ("personnel")
  16. # Stores the argument in a property called astNodeName whose sole purpose
  17. # is to support Print()
  18.  
  19. sub New {
  20.     my ($this) = {"astNodeName" => $_[0]};
  21.     bless ($this);
  22.     return $this;
  23. }
  24.  
  25. # Add a property to this object
  26. # $astNode->AddProp("className", "Employee");
  27.  
  28. sub AddProp {
  29.     my ($this) = $_[0];
  30.     $this->{$_[1]} = $_[2];
  31. }
  32.  
  33. # Equivalent to AddProp, except the property name is associated
  34. # with a list of values
  35. # $classAstNode->AddProp("attrList", $attrAstNode);
  36.  
  37. sub AddPropList {
  38.     my ($this) = $_[0];
  39.     if (! exists $this->{$_[1]}) {
  40.         $this->{$_[1]} = [];
  41.     }
  42.     push (@{$this->{$_[1]}}, $_[2]);
  43. }
  44.  
  45. # Returns a list of all the property names of this object
  46. sub GetProps {
  47.     my ($this) = $_[0];
  48.     return keys %{$this};
  49. }
  50.  
  51. 1;
  52.